package main

import (
	"database/sql"
	"fmt"

	_ "github.com/mattn/go-sqlite3"
)

// const databasePath = "/config/workspace/go-learn/ch01/sqlite/db/"
const databasePath = "D:\\GoPro\\go-learn\\ch01\\sqlite\\db\\"

func main() {
	db, err := sql.Open("sqlite3", databasePath+"GoSqLite.db")
	checkErr(err)

	//插入
	stmt, err := db.Prepare("INSERT INTO userinfo(username, department, created) values(?,?,?)")
	checkErr(err)

	res, err := stmt.Exec("hehe", "depp", "2024-01-22")
	checkErr(err)

	id, err := res.LastInsertId()
	checkErr(err)

	fmt.Println(id)
}

func checkErr(err error) {
	if err != nil {
		panic(err)
	}
}

/**
需要安装gcc环境
go env CGO_ENABLED
go env -w CGO_ENABLED=1
su 密码 ：lc991122
sudo apt update
sudo apt install build-essential gdb
*/
